package com.cnunicom.modules.tra.controller;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.cnunicom.common.utils.DateUtils;
import com.cnunicom.modules.tra.vo.ResRecMebDisVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cnunicom.modules.tra.entity.ResRecordEntity;
import com.cnunicom.modules.tra.service.ResRecordService;
import com.cnunicom.common.utils.PageUtils;
import com.cnunicom.common.utils.R;

import javax.validation.Valid;


/**
 * 就餐记录表
 *
 * @author dzygod
 * @email dingziyuan0@gmail.com
 * @date 2020-03-04 09:39:59
 */
@RestController
@RequestMapping("tra/resrecord")
public class ResRecordController {
    @Autowired
    private ResRecordService resRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("tra:resrecord:list")
    public R list(@RequestParam Map<String, Object> params){
//        List<Object> objectList = resRecordService.queryResRecMebDisPage(params);
        List<Object> objectList = resRecordService.queryPage(params);
        PageUtils page = (PageUtils)objectList.get(0);
        BigDecimal totalPrice = (BigDecimal)objectList.get(1);
        return R.ok().put("page", page).put("totalPrice",totalPrice);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("tra:resrecord:info")
    public R info(@PathVariable("id") Integer id){
//		ResRecMebDisVO resRecord = resRecordService.getById(id);
        ResRecordEntity resRecord = resRecordService.getById(id);

        return R.ok().put("resRecord", resRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("tra:resrecord:save")
    public R save(@RequestBody @Valid ResRecordEntity resRecord){
        resRecord.setCreateTime(DateUtils.getDateTime());
        resRecord.setIsDel(0);
		resRecordService.save(resRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("tra:resrecord:update")
    public R update(@RequestBody ResRecordEntity resRecord){
		resRecordService.updateById(resRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("tra:resrecord:delete")
    public R delete(@RequestBody Integer[] ids){
		resRecordService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
